package com.xbongbong.paas.service.dynamic.crm.strategy;

import com.xbongbong.paas.service.dynamic.crm.strategy.impl.DynamicStrategyEmptyImpl;
import com.xbongbong.parent.factory.BusinessDynamicFactory;
import com.xbongbong.parent.interfaces.DynamicStrategy;
import com.xbongbong.saas.enums.ProjectLogEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;
import java.util.Objects;

/**
 *动态策略工厂
 *
 *@author weijianxun
 */
@Service
public class DynamicStrategyFactory {

    @Resource
    private Map<Integer, DynamicStrategy> typeToDynamicStrategyMap;
    @Resource
    private Map<Integer, CustomerDynamicStrategy> typeToCustomerDynamicStrategyMap;
    @Resource
    private Map<Integer, TeamDynamicStrategy> typeToTeamDynamicStrategyMap;
    @Resource
    private Map<Integer, CommunicateDynamicStrategy> typeToCommunicateDynamicStrategyMap;
    @Resource
    private Map<Integer, SmsDynamicStrategy> typeToSmsDynamicStrategyMap;
    @Autowired
    private Map<Integer, PushNotifyDynamicStrategy> pushNotifyDynamicStrategyMap;
    @Resource
    private Map<Integer, PaymentSheetDynamicStrategy> typeToPaymentSheetDynamicStrategyMap;
    @Resource
    private Map<Integer, DecisionTreeDynamicStrategy> typeToDecisionTreeDynamicStrategyMap;
    @Resource
    private Map<Integer, PayDynamicStrategy> typeToPayDynamicStrategyMap;
    @Resource
    private Map<Integer, MainBusinessDynamicStrategy> typeToMainBusinessDynamicStrategyMap;
    @Resource
    private Map<Integer, CompetitorDynamicStrategy> typeToCompetitorDynamicStrategyMap;
    @Resource
    private BusinessDynamicFactory businessDynamicFactory;

    private final DynamicStrategyEmptyImpl dynamicStrategyEmpty = new DynamicStrategyEmptyImpl();

    public MainBusinessDynamicStrategy getMainBusinessDynamicStrategy(Integer logType) {
        MainBusinessDynamicStrategy mainBusinessDynamicStrategy = typeToMainBusinessDynamicStrategyMap.get(ProjectLogEnum.getBusinessTypeBySubType(logType).getCode());
        return Objects.nonNull(mainBusinessDynamicStrategy) ? mainBusinessDynamicStrategy : dynamicStrategyEmpty;
    }

    public MainBusinessDynamicStrategy getMainBusinessDynamicStrategyByBusinessType(Integer businessType) {
        MainBusinessDynamicStrategy mainBusinessDynamicStrategy = typeToMainBusinessDynamicStrategyMap.get(businessType);
        return Objects.nonNull(mainBusinessDynamicStrategy) ? mainBusinessDynamicStrategy : dynamicStrategyEmpty;
    }

    /**
     * 应收款
     */
    public PayDynamicStrategy getPayDynamicStrategy(Integer logType) {
        PayDynamicStrategy payDynamicStrategy = typeToPayDynamicStrategyMap.get(ProjectLogEnum.getBusinessTypeBySubType(logType).getCode());
        return Objects.nonNull(payDynamicStrategy) ? payDynamicStrategy : dynamicStrategyEmpty;
    }

    public PayDynamicStrategy getPayDynamicStrategyByBusinessType(Integer businessType) {
        PayDynamicStrategy payDynamicStrategy = typeToPayDynamicStrategyMap.get(businessType);
        return Objects.nonNull(payDynamicStrategy) ? payDynamicStrategy : dynamicStrategyEmpty;
    }

    /**
     * 回款单
     */
    public PaymentSheetDynamicStrategy getPaymentSheetDynamicStrategyByBusinessType(Integer businessType){
        PaymentSheetDynamicStrategy paymentSheetDynamicStrategy = typeToPaymentSheetDynamicStrategyMap.get(businessType);
        return Objects.nonNull(paymentSheetDynamicStrategy) ? paymentSheetDynamicStrategy : dynamicStrategyEmpty;
    }

    /**
     * 动态
     * @param logType
     * @return
     */
    public DynamicStrategy getDynamicStrategy(Integer logType) {
        DynamicStrategy dynamicStrategy = typeToDynamicStrategyMap.get(ProjectLogEnum.getBusinessTypeBySubType(logType).getCode());
        return Objects.nonNull(dynamicStrategy) ? dynamicStrategy : dynamicStrategyEmpty;
    }

    public DynamicStrategy getDynamicStrategyByBusinessType(Integer businessType) {
        DynamicStrategy dynamicStrategy = typeToDynamicStrategyMap.get(businessType);
        return Objects.nonNull(dynamicStrategy) ? dynamicStrategy : dynamicStrategyEmpty;
    }

    /**
     * 客户
     * @param logType
     * @return
     */
    public CustomerDynamicStrategy getCustomerDynamicStrategy(Integer logType) {
        CustomerDynamicStrategy customerDynamicStrategy = typeToCustomerDynamicStrategyMap.get(ProjectLogEnum.getBusinessTypeBySubType(logType).getCode());
        return Objects.nonNull(customerDynamicStrategy) ? customerDynamicStrategy : dynamicStrategyEmpty;
    }

    public CustomerDynamicStrategy getCustomerDynamicStrategyByBusinessType(Integer businessType) {
        CustomerDynamicStrategy customerDynamicStrategy = typeToCustomerDynamicStrategyMap.get(businessType);
        return Objects.nonNull(customerDynamicStrategy) ? customerDynamicStrategy : dynamicStrategyEmpty;
    }

    /**
     * 团队
     * @param businessType
     * @return
     */
    public TeamDynamicStrategy getTeamDynamicStrategyByBusinessType(Integer businessType) {
        TeamDynamicStrategy teamDynamicStrategy = typeToTeamDynamicStrategyMap.get(businessType);
        return Objects.nonNull(teamDynamicStrategy) ? teamDynamicStrategy : dynamicStrategyEmpty;
    }

    /**
     * 跟进
     * @param logType
     * @return
     */
    public CommunicateDynamicStrategy getCommunicateDynamicStrategy(Integer logType) {
        CommunicateDynamicStrategy communicateDynamicStrategy = typeToCommunicateDynamicStrategyMap.get(ProjectLogEnum.getBusinessTypeBySubType(logType).getCode());
        return Objects.nonNull(communicateDynamicStrategy) ? communicateDynamicStrategy : dynamicStrategyEmpty;
    }

    public CommunicateDynamicStrategy getCommunicateDynamicStrategyByBusinessType(Integer businessType) {
        CommunicateDynamicStrategy communicateDynamicStrategy = typeToCommunicateDynamicStrategyMap.get(businessType);
        return Objects.nonNull(communicateDynamicStrategy) ? communicateDynamicStrategy : dynamicStrategyEmpty;
    }

    /**
     * 短信往来
     */
    public SmsDynamicStrategy getSmsDynamicStrategy(Integer logType) {
        SmsDynamicStrategy smsDynamicStrategy = typeToSmsDynamicStrategyMap.get(ProjectLogEnum.getBusinessTypeBySubType(logType).getCode());
        return Objects.nonNull(smsDynamicStrategy) ? smsDynamicStrategy : dynamicStrategyEmpty;
    }

    public SmsDynamicStrategy getSmsDynamicStrategyByBusinessType(Integer businessType) {
        SmsDynamicStrategy smsDynamicStrategy = typeToSmsDynamicStrategyMap.get(businessType);
        return Objects.nonNull(smsDynamicStrategy) ? smsDynamicStrategy : dynamicStrategyEmpty;
    }

    public PushNotifyDynamicStrategy getPushNotifyDynamicStrategy() {
        PushNotifyDynamicStrategy strategy = pushNotifyDynamicStrategyMap.get(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode());
        return strategy;
    }

    public DecisionTreeDynamicStrategy getDecisionTreeDynamicStrategy(Integer businessType) {
        DecisionTreeDynamicStrategy strategy = typeToDecisionTreeDynamicStrategyMap.get(businessType);
        return strategy;
    }

    public CompetitorDynamicStrategy getCompetitorDynamicStrategy(Integer logType) {
        CompetitorDynamicStrategy competitorDynamicStrategy = typeToCompetitorDynamicStrategyMap.get(ProjectLogEnum.getBusinessTypeBySubType(logType).getCode());
        return Objects.nonNull(competitorDynamicStrategy) ? competitorDynamicStrategy : dynamicStrategyEmpty;
    }

    public CompetitorDynamicStrategy getCompetitorDynamicstrategyByBusinessType(Integer businessType){
        CompetitorDynamicStrategy competitorDynamicStrategy = typeToCompetitorDynamicStrategyMap.get(businessType);
        return Objects.nonNull(competitorDynamicStrategy) ? competitorDynamicStrategy: dynamicStrategyEmpty;
    }

}
